package com.lucifer.d.security.gateway.config;

import com.lucifer.d.security.config.conditional.OnSecurityCondition;
import com.lucifer.d.security.gateway.config.conditional.GateWayServerCondition;
import com.lucifer.d.security.gateway.service.filter.SecurityFilter;
import com.lucifer.d.security.model.property.DefaultPermitProperty;
import com.lucifer.d.security.model.property.PermitProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @author Lucifer
 * @create 2023 - 03 - 31 11:11
 */
@Configuration
@EnableConfigurationProperties({PermitProperty.class})
public class LuciferSecurityConfiguration {

    /**
     * 网关过滤filter注入
     *
     * @return
     */
    @Conditional({OnSecurityCondition.class, GateWayServerCondition.class})
    @Bean
    public SecurityFilter securityFilter(PermitProperty property){
        List<String> permit = property.getPermits();
        if (property.getUseDefault()){
            permit.addAll(DefaultPermitProperty.getPermit());
        }
        return new SecurityFilter(permit);
    }

}
